package com.liwbn.rbac.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liwbn.rbac.core.orm.mybatis.Page;
import com.liwbn.rbac.dao.RoleMapper;
import com.liwbn.rbac.model.Role;
import com.liwbn.rbac.model.RoleExample;
import com.liwbn.rbac.service.RoleService;
import com.liwbn.rbac.vo.RolePermissionVO;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMappler;

    @Override
    public Long insert(Role model) {
        return roleMappler.insert(model);
    }

    @Override
    public int insertSelective(Role model) {
        return roleMappler.insertSelective(model);
    }

    @Override
    public int updateByPrimaryKey(Role model) {
        return roleMappler.updateByPrimaryKey(model);
    }

    @Override
    public int updateByPrimaryKeySelective(Role model) {
        return roleMappler.updateByPrimaryKeySelective(model);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return roleMappler.deleteByPrimaryKey(id);
    }

    @Override
    public Role selectByPrimaryKey(Long id) {
        return roleMappler.selectByPrimaryKey(id);
    }

    @Override
    public Page<Role> selectPage(Integer pageNo, Integer pageSize) {
        Page<Role> page = new Page<Role>(pageNo, pageSize);
        roleMappler.selectByExample(page, null);
        return page;
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        RoleExample example = new RoleExample();
        RoleExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(ids);
        roleMappler.deleteByExample(example);
    }

    @Override
    public List<Role> selectAllRoles() {
        return roleMappler.selectByExample(null);
    }

    @Override
    public List<RolePermissionVO> selectAllRolesAndPermission() {
        return roleMappler.selectAllRolesAndPermission(null);
    }

    @Override
    public List<Role> selectRolesByUserName(String userName){
        return roleMappler.selectRolesByUserName(userName);
    }
}
